package com.icbc.springcloud.controller;

import com.icbc.springcloud.pojo.Dept;
import com.icbc.springcloud.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//提供restful服务
@RestController
@Slf4j
public class DeptController {
    @Autowired
    private DeptService service;

    //添加一般用post
    @PostMapping(value = "/dept/add")
    public boolean addDept(Dept dept){
        System.out.println(dept.toString());
        return service.insertDept(dept);
    }

    @PostMapping(value = "/dept/add/test")
    public boolean addPram(@RequestParam("dname") String dname){
        Dept dept=new Dept();
        dept.setDname(dname);
       return service.insertDept(dept);
    }

    @RequestMapping("/dept/test/add")
    public boolean addDept_test(Dept dept){
        return service.insertDept(dept);
    }

    @GetMapping("/dept/get/{id}")
    public Dept getDept(@PathVariable("id")int id){
        log.error("get dept");
        return service.queryById(id);
    }

    @GetMapping("/dept/get/all")
    public List<Dept> getAllDept(){
        log.info("query all" );
        log.info(String.valueOf(service.queryAll()));
        return service.queryAll();
    }

    @RequestMapping("/dept/hello")
    public String sayHello(){
        System.out.println("中文，你好！");
        return "中文，你好!";
    }

}
